package com.ewzj.bigdata.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;

import com.ewzj.bigdata.R;
import com.ewzj.bigdata.app.constants.AppConstants;
import com.ewzj.bigdata.di.component.DaggerLoginComponent;
import com.ewzj.bigdata.di.module.LoginModule;
import com.ewzj.bigdata.mvp.contract.LoginContract;
import com.ewzj.bigdata.mvp.presenter.LoginPresenter;
import com.ewzj.bigdata.mvp.ui.fragment.LoginFragmentFragment;
import com.ewzj.bigdata.mvp.ui.fragment.RegisterFragment;
import com.ewzj.bigdata.mvp.ui.widget.PagerSlidingTabStrip;
import com.jess.arms.base.AdapterViewPager;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.umeng.socialize.UMShareAPI;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {


    @BindView(R.id.tabs)
    PagerSlidingTabStrip tabs;
    @BindView(R.id.vp_loginandregister)
    ViewPager vpLoginandregister;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerLoginComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .loginModule(new LoginModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        intitab();
    }

    private void intitab(){
        String[] mTitles = AppConstants.LOGIN_REGISTER;
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(LoginFragmentFragment.newInstance());
        fragments.add(RegisterFragment.newInstance());
        FragmentManager fragmentManager = getSupportFragmentManager();
        AdapterViewPager adapterViewPager = new AdapterViewPager(fragmentManager, fragments, mTitles);
        vpLoginandregister.setAdapter(adapterViewPager);
        tabs.setPadding(10,0,10,0);
        tabs.setViewPager(vpLoginandregister);
    }
    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
    }
}
